﻿@using System.Web.Routing;
@using Orchard.Utility.Extensions;
@{
    IEnumerable<dynamic> firstLevelMenuItems = Model;

    Model.Attributes.Add("role", "local-navigation");
    var tag = Tag(Model, "ul");
}
﻿@tag.StartElement
    @foreach(var firstLevelMenuItem in Model) {
        if (firstLevelMenuItem.LocalNav) {
            string sectionHeaderText = firstLevelMenuItem.Text.Text;

            var sectionHeaderMarkup = firstLevelMenuItem.RouteValues != null || HasText(firstLevelMenuItem.Url)
                ? Html.Link(sectionHeaderText, (string)firstLevelMenuItem.Href)
                : new HtmlString(string.Format("<span>{0}</span>", Html.Encode(sectionHeaderText)));

            if (firstLevelMenuItem == firstLevelMenuItems.First()) {
                firstLevelMenuItem.Classes.Add("first");
            }

            if (firstLevelMenuItem != firstLevelMenuItems.First()) {
                firstLevelMenuItem.Classes.Add("middle");
            }

            if (firstLevelMenuItem == firstLevelMenuItems.Last()) {
                firstLevelMenuItem.Classes.Add("last");
            }

            if (firstLevelMenuItem.Selected) {
                firstLevelMenuItem.Classes.Add("selected");
            }

            firstLevelMenuItem.Classes.Add("local-section-" + sectionHeaderText.HtmlClassify());
            var firstLevelTag = Tag(firstLevelMenuItem, "li");
            @firstLevelTag.StartElement
                @sectionHeaderMarkup
           @firstLevelTag.EndElement
        }
    }
@tag.EndElement
